import scrapy
from scrapy import Selector, Request
from spider2107.items import BKItem


class BKItemSpider(scrapy.Spider):
    n_id = 2
    name = 'beike'
    allowed_domains = ['ke.com']
    start_urls = ['https://bj.ke.com/ershoufang/pg1/']
    # name = "beike"
    # allowed_domains = ["su.ke.com"]
    # start_urls = ["https://su.ke.com/ershoufang/chengnan1"]

    # def start_requests(self):
    #     for page in range(100):
    #         # yield Request(url=f'https://su.ke.com/ershoufang/chengnan1/pg{page}/')
    #         yield Request(url=f'https://su.ke.com/ershoufang/chengnan1/pg2/')

    def parse(self, response):
        item = BKItem()
        for bk in response.xpath("//div[@data-component='list']/ul/li"):
            TITLE = bk.xpath(".//div[@class='info clear']/div[@class='title']/a/text()").extract()
            POSITION_INFO = bk.xpath(".//div[@class='positionInfo']/a/text()").extract()
            TOTAL_PRICE = bk.xpath(".//div[@class='totalPrice']/span/text()").extract()
            item['title'] = TITLE[0]
            item['positionInfo'] = '123'
            item['totalPrice'] = '456'
            yield item
        # 解析器
        # sel = Selector(response)
        # 解析出电影列表
        # 号为id选择器， > 子元素选择器
        # node_list = response.xpath('//ul[@class="sellListContent"]')

        # for item in node_list:
        #     print('找到item吗！！！！---',item)

        #     bk_item = BKItem()
        #     bk_item['title'] = item.css('span.title::text').extract_first()
        #     yield bk_item

